<template>
  <div class="app-container">
    <wise-crud
      ref="wise-crud"
      :urls="urls"
      :fields="fields"
      :handle="handle"
      :filters="filters"
    />
  </div>
</template>
<script>
import WiseCrud from '@/components/Crud/wiseCrud'
import { imgPath } from '../../../../filters'

export default {
  name: 'PatrolTypeManage',
  components: { WiseCrud },
  data() {
    return {
      urls: {
        list: '/api/v1/welder-sbtx-second/patrol-type-comb/list',
        add: '/api/v1/welder-sbtx-second/patrol-type-comb/create',
        show: '/api/v1/welder-sbtx-second/patrol-type-comb/show/',
        update: '/api/v1/welder-sbtx-second/patrol-type/update/',
        delete: '/api/v1/welder-sbtx-second/patrol-type/remove/'
      }
    }
  },
  computed: {
    spaceId() {
      return this.$store.state.project.spaceId
    },
    entSpaceId() {
      return this.$store.getters.entSpaceId
    },
    handle() {
      // if (this.$store.state.user.project) {
      //   return ['add']
      // } else {
      //   return ['add', 'filters']
      // }
      return ['add']
    },
    fields() {
      let arr = [{ label: '序号', type: 'index', use: ['table'] }]
      if (this.$store.state.user.project) {
        arr.push({
          prop: 'projectId',
          defaultValue: this.$store.state.user.project.id,
          use: ['add', 'edit']
        })
      }
      // arr.push({
      //   label: '所属项目',
      //   prop: 'projectInfo',
      //   type: 'select',
      //   labelWidth: '130px',
      //   url: '/api/v1/welder-sbtx-second/project-info',
      //   labelKey: 'name',
      //   valueKey: 'id',
      //   objKeys: [
      //     {
      //       field: 'projectId',
      //       key: 'id'
      //     }
      //   ],
      //   rules: [
      //     { required: true, message: '请选择项目', trigger: 'change' }
      //   ],
      //   placeholder: '请选择项目',
      //   use: ['add', 'edit', 'filters']
      // })
      // arr.push({
      //   label: '所属项目',
      //   prop: 'manage',
      //   type: 'render',
      //   labelWidth: '130px',
      //   tableRender: (h, row, index) => {
      //     return h('div', row.projectInfo ? row.projectInfo.name : '')
      //   },
      //   viewRender: (h, item, object) => {
      //     return h('div', object.projectInfo ? object.projectInfo.name : '')
      //   },
      //   use: ['table', 'view']
      // })
      arr.push(
        {
          label: '巡检对象名称',
          prop: 'name',
          type: 'text',
          labelWidth: '130px',
          rules: [
            {
              required: true,
              message: '请输入巡检对象名称',
              trigger: 'change'
            }
          ],
          placeholder: '请输入巡检对象名称',
          use: ['table', 'add', 'view', 'edit', 'search']
        },
        {
          label: '上传人',
          prop: 'user',
          type: 'render',
          labelWidth: '130px',
          tableRender: (h, row, index) => {
            if (row.user) {
              return h('div', { style: { display: 'inline-flex' }}, [
                h(
                  'el-avatar',
                  {
                    props: {
                      src: imgPath(row.user.picture)
                    }
                  },
                  row.user.username
                ),
                h(
                  'div',
                  {
                    style: {
                      height: '40px',
                      lineHeight: '44px',
                      marginLeft: '10px'
                    }
                  },
                  row.user.username
                )
              ])
            } else {
              return h('div', '')
            }
          },
          viewRender: (h, item, object) => {
            if (object.user) {
              return h('div', { style: { display: 'inline-flex' }}, [
                h(
                  'el-avatar',
                  {
                    props: {
                      src: imgPath(object.user.picture)
                    }
                  },
                  object.user.username
                ),
                h(
                  'div',
                  {
                    style: {
                      height: '40px',
                      lineHeight: '44px',
                      marginLeft: '10px'
                    }
                  },
                  object.user.username
                )
              ])
            } else {
              return h('div', '')
            }
          },
          use: ['table', 'view', 'search']
        },
        {
          label: '所属岗位',
          prop: 'jobInfo',
          type: 'select',
          labelWidth: '130px',
          url: '/api/v1/welder-uac-second/base-profession-comb/list',
          labelKey: 'name',
          valueKey: 'id',
          objKeys: [
            {
              field: 'jobId',
              key: 'id'
            }
          ],
          filters: [
            {
              field: 'spaceId',
              operator: 'EQUALS',
              value: this.entSpaceId
            }
          ],
          rules: [{ required: true, message: '请选择岗位', trigger: 'change' }],
          placeholder: '请选择岗位',
          use: ['add', 'edit', 'filters']
        },
        {
          label: '所属岗位',
          prop: 'manage',
          type: 'render',
          labelWidth: '130px',
          tableRender: (h, row, index) => {
            return h('div', row.jobInfo ? row.jobInfo.name : '')
          },
          viewRender: (h, item, object) => {
            return h('div', object.jobInfo ? object.jobInfo.name : '')
          },
          use: ['table', 'view']
        },
        {
          prop: 'spaceId',
          defaultValue: this.$store.state.project.spaceId,
          use: ['add', 'edit']
        }
      )
      arr.push({
        label: '操作',
        type: 'handle',
        use: ['table'],
        handle: ['edit', 'view', 'delete'],
        tableWidth: 300
      })
      return arr
    },
    filters() {
      return [
        {
          field: 'spaceId',
          operator: 'EQUALS',
          value: this.$store.state.project.spaceId
        }
      ]
    }
  },
  methods: {}
}
</script>

<style>
</style>
